package com.station.administrators.controller;

import com.open.capacity.common.web.Result;
import com.open.capacity.common.model.NavigationModel;
import com.station.administrators.service.NavigationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangGang
 * @Title: 导航管理
 * @Description: TODO
 * @date 2021/6/29/11:00
 */
@RestController
@RequestMapping("/nav")
public class NavigationController {
    @Autowired
    private NavigationService navigationService;

    @PostMapping("/add")
    @PreAuthorize("hasAuthority('nav:add')")
    public Object add(@RequestBody NavigationModel navigation){
        navigationService.add(navigation);
        return Result.succeed("成功！");
    }
    @PostMapping("/update")
    @PreAuthorize("hasAuthority('nav:post/nav/add')")
    public Object update(NavigationModel navigation){
        navigationService.update(navigation);
        return Result.succeed("修改成功！");
    }
    @PostMapping("/delete/{id}")
    @PreAuthorize("hasAuthority('nav:post/nav/update')")
    public Object delete(@PathVariable Long id){
        navigationService.delete(id);
        return Result.succeed("删除成功！");
    }
    @GetMapping("/findById")
    @PreAuthorize("hasAuthority('nav:get/nav/findById')")
    public Object findById(Long id){
        NavigationModel navigation=navigationService.findById(id);
        return Result.succeed(navigation,"！");
    }
    @GetMapping("/findAll")
    @PreAuthorize("hasAuthority('nav:get/nav/findAll')")
    public Object findAll(NavigationModel navigation){
        List<NavigationModel> navigationList=navigationService.findAll(navigation);
        Integer count=navigationService.getCount(navigation);
        Map<String,Object> map=new HashMap<>();
        map.put("navigationList",navigationList);
        map.put("count",count);
        return Result.succeed(map,"所有导航！");
    }

}
